package hip.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DBObjHelper {

    public static Date stringToDate(String dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh-mm-ss");
        try {
            return sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static float dbObjToFloat(Object object) {
        String value = dbObjToString(object);
        if (value != null && value != "")
            return Float.valueOf(value);
        return 0;
    }

    public static int dbObjToInt(Object object) {
        String value = dbObjToString(object);
        if (value != null && value != "")
            return Integer.valueOf(value);
        return 0;
    }

    public static String dbObjToString(Object object) {
        if (object != null)
            return object.toString();
        return "";
    }

    public static Date dbObjToDate(Object object) {
        if (object != null)
            return (Date) object;
        return null;
    }

    public static boolean dbObjToBool(Object object) {
        return dbObjToString(object).equals("1");
    }
}
